package com.mac.core.activemq;

import com.mac.core.conf.JmsConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;

import javax.jms.Destination;

/**
 * 生产者
 */
@Component
public class JMSProducer {
    @Autowired
    private JmsTemplate jmsTemplate;

    /**
     * 发射消息
     * @param destination 发送到的队列
     * @param message 待发送的消息
     */
    public void sendMessage(Destination destination, String message) {
        System.out.println(jmsTemplate.getDeliveryMode());
        this.jmsTemplate.convertAndSend(destination,message);
    }

    /**
     * 发送消息
     * @param message 待发送的消息
     */
    public void sendMessage(final String message) {
        System.out.println(jmsTemplate.getDeliveryMode());
        jmsTemplate.convertAndSend(JmsConfig.QUEUE,message);
    }

}